package com.heima.xiyuanmall.sudoku.sample;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import androidx.annotation.NonNull;

import com.heima.xiyuanmall.sudoku.CellStyle;
import com.heima.xiyuanmall.sudoku.Pos;
import com.heima.xiyuanmall.sudoku.RenderEventsHolder;

import java.util.Collection;

/**
 * @author flutterdash@qq.com
 * @since 2021/10/3 21:43
 */
public class JavaSample {

    private Handler handler;

    public void onCreate() {
        handler = new Handler() {
            @SuppressLint("HandlerLeak")
            @Override
            public void handleMessage(@NonNull Message msg) {
                handler(msg);
            }
        };
    }

    public void handler(Message message) {
        doHandler((RenderEventsHolder) message.obj);
    }

    private void doHandler(RenderEventsHolder holder) {
        Collection<CellStyle> events = holder.getEvents();
        for (CellStyle event : events) {
            event.getRenderer().render(getView(event.getPos()));
        }
    }

    /**
     * @param pos 数独表格上的一个坐标
     * @return    根据这个坐标返回对应单元格的View对象
     */
    private View getView(Pos pos) {
        return null;
    }

}
